package com.ruoyi.archive.service.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.archive.domain.SSoldierBaseInfo;
import com.ruoyi.archive.domain.STransferredCadres;
import com.ruoyi.archive.service.ISTransferredCadresService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.archive.mapper.SRetiredSoldierMapper;
import com.ruoyi.archive.domain.SRetiredSoldier;
import com.ruoyi.archive.service.ISRetiredSoldierService;

/**
 * 退役士兵信息采集		Service业务层处理
 *
 * @author Allen
 * @date 2021-09-28
 */
@Service
public class SRetiredSoldierServiceImpl extends ServiceImpl<SRetiredSoldierMapper, SRetiredSoldier> implements ISRetiredSoldierService {
    @Autowired
    private SRetiredSoldierMapper sRetiredSoldierMapper;
    @Autowired
    private ISTransferredCadresService transferredCadresService;

    /**
     * 查询退役士兵信息采集分
     *
     * @param id
     *         退役士兵信息采集分		主键
     *
     * @return 退役士兵信息采集分
     */
    @Override
    public SRetiredSoldier selectSRetiredSoldierById(Long id) {
        return sRetiredSoldierMapper.selectSRetiredSoldierById(id);
    }

    /**
     * 查询退役士兵信息采集分		列表
     *
     * @param sRetiredSoldier
     *         退役士兵信息采集分
     *
     * @return 退役士兵信息采集分
     */
    @Override
    public List<SRetiredSoldier> selectSRetiredSoldierList(SRetiredSoldier sRetiredSoldier) {
        List<SRetiredSoldier> retiredSoldierList = sRetiredSoldierMapper.selectSRetiredSoldierList(sRetiredSoldier);
        if (CollectionUtil.isNotEmpty(retiredSoldierList)) {
            List<Long> soldierIdList = retiredSoldierList.stream().map(SRetiredSoldier::getSoldierId).collect(Collectors.toList());
            Map<Long, SSoldierBaseInfo> baseInfoMap = transferredCadresService.getSoldierBaseInfoMap(soldierIdList);
            retiredSoldierList.stream().forEach(x -> x.setSoldierName(baseInfoMap.get(x.getSoldierId()).getName()));
            retiredSoldierList.stream().forEach(x -> x.setIdCard(baseInfoMap.get(x.getSoldierId()).getIdCard()));
        }
        return retiredSoldierList;
    }

    /**
     * 新增退役士兵信息采集分
     *
     * @param sRetiredSoldier
     *         退役士兵信息采集分
     *
     * @return 结果
     */
    @Override
    public int insertSRetiredSoldier(SRetiredSoldier sRetiredSoldier) {
        return sRetiredSoldierMapper.insertSRetiredSoldier(sRetiredSoldier);
    }

    /**
     * 修改退役士兵信息采集分
     *
     * @param sRetiredSoldier
     *         退役士兵信息采集分
     *
     * @return 结果
     */
    @Override
    public int updateSRetiredSoldier(SRetiredSoldier sRetiredSoldier) {
        return sRetiredSoldierMapper.updateSRetiredSoldier(sRetiredSoldier);
    }

    /**
     * 批量删除退役士兵信息采集分
     *
     * @param ids
     *         需要删除的退役士兵信息采集分		主键
     *
     * @return 结果
     */
    @Override
    public int deleteSRetiredSoldierByIds(Long[] ids) {
        return sRetiredSoldierMapper.deleteSRetiredSoldierByIds(ids);
    }

    /**
     * 删除退役士兵信息采集分		信息
     *
     * @param id
     *         退役士兵信息采集分		主键
     *
     * @return 结果
     */
    @Override
    public int deleteSRetiredSoldierById(Long id) {
        return sRetiredSoldierMapper.deleteSRetiredSoldierById(id);
    }
}
